<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome ${ user.firstname }</title>
</head>
<body>

<h1>HOME</h1>

<c:if test="${(not empty user)}">
	<table>
		<tr>
			<td rowspan="7"><a href=${ user.profileImage.location }><img alt="Greška, nema slike" src="${user.profileImage.thumbnailLocation}"></a></td>		
		</tr>
		<tr>
			<td><c:out value="Name: ${ user.firstname }"></c:out></td>
		</tr>
		<tr>
			<td><c:out value="Last name: ${ user.lastname }"></c:out></td>
		</tr>
		<tr>
			<td><c:out value="Email address: ${ user.emailAddress }"></c:out></td>		
		</tr>
		<tr>
			<td><c:out value="Gender: ${ user.gender }"></c:out></td>		
		</tr>
		<tr>
			<td><c:out value="Date of Birth: ${ user.dateOfBirth }"></c:out></td>		
		</tr>
		<tr>
			<td>
				<c:if test="${ user.emailNotifications == true }">
					<c:out value="Receiving email notifications"></c:out>
				</c:if>
				<c:if test="${ user.emailNotifications != true }">
					<c:out value="Not receiving email notifications"></c:out>
				</c:if>
			</td>		
		</tr>
	
	</table>
	
	<a href="followers.jsp">Followers</a> <br/>
	
	<a href="./ViewUserController?id=${ user.id }">View profile</a><br/>
	
	<a href="./search.jsp">Search</a><br/>
	
	<a href="./editUser.jsp">Edit personal information</a><br/>
	
	<a href="./PreUploadImageController">Upload image</a><br/>
	
	<a href="createAlbum.jsp">Create album</a><br/>
	
	<a href="./LogoutController">Log out</a><br/>

	
	<br/>
	<h2>My albums:</h2>
	<table>
		<c:if test="${ empty userAlbums }">
			<tr>
				<td>- NO ALBUMS -</td>
			</tr>
		</c:if>
		<c:if test="${ not empty userAlbums }">
			<c:forEach var="album" items="${userAlbums}">
				<tr>
					<td> <label>Album title: </label> </td>
					<td>
						<a href="./ViewAlbumController?id=${album.id}">
						<c:out value="${album.title}"/>
						</a>
					</td>
				</tr>
			</c:forEach>
		</c:if>
	</table>
	
	
	<br><br>
	<h2>My recent comments on public photos: </h2>
	<c:if test="${ empty requestScope.recentComments }">
		No recent comments
	</c:if>
	<c:if test="${ not empty requestScope.recentComments }">
		<table>
			<c:forEach var="currentComment" items="${ requestScope.recentComments }" varStatus="status">
				<c:if test="${ currentComment.photo.publiclyAvailable }">
					<tr>
						<td>
							<a href="./ViewPhotoController?id=${ currentComment.photo.id }">
								<img alt="Greška, nema slike" src="${ currentComment.photo.thumbnailLocation }">
							</a>
						</td>
						<td>
							<c:out value="${ status.count }."></c:out>
							<a href="./ViewUserController?id=${ currentComment.user.id }">
							<c:out value="${ currentComment.user.firstname } ${ currentComment.user.lastname }"></c:out>
							</a>
							<c:out value=" - ${ currentComment.date }"></c:out>
							<br/>
							<c:out value="${ currentComment.title } - ${ currentComment.contents }"></c:out>
						</td>
					</tr>
				</c:if>
			</c:forEach>
		</table>
	</c:if>
	
</c:if>

<br><br>

<c:if test="${( empty user)}">
	<a href="./login.jsp">Log in</a> <br>
	<a href="./register.jsp">Register</a> <br>
</c:if>

	<h2>Last 12 public photos</h2>
	<c:set var="counter" value="0"/>
	<table>
		<c:forEach var="currentPhoto" items="${ requestScope.nPhotos }">
			<c:if test="${ currentPhoto.publiclyAvailable }">
				<c:set var="counter" value="${counter + 1}"/>
				<tr>
					<td>
						<c:out value="${counter}."/>
					</td>
					<td>
						<a href="./ViewPhotoController?id=${ currentPhoto.id }"><img alt="Greška, nema slike" src="${ currentPhoto.thumbnailLocation }"></a>
					</td>
				</tr>
			</c:if>
		</c:forEach>
	</table>
	
</body>
</html>